package com.rx.cxftest1.config;

import com.rx.cxftest1.webservice.DoCheckService;
import org.apache.cxf.Bus;
import org.apache.cxf.jaxws.EndpointImpl;
import org.apache.cxf.phase.Phase;
import org.apache.cxf.transport.servlet.CXFServlet;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.xml.ws.Endpoint;
import java.util.List;


@Configuration
public class CXFConfig {

    @Autowired
    private Bus bus;

    @Autowired
    private DoCheckService doCheckService;


    /**
     * 此方法被注释后:wsdl访问地址为http://127.0.0.1:8080/services/user?wsdl
     * 去掉注释后：wsdl访问地址为：http://127.0.0.1:8080/{endpoint}?wsdl
     */
    @Bean
    public ServletRegistrationBean dispatcherServlet(){
        return new ServletRegistrationBean(new CXFServlet(),"/*");
    }


    /**
     * 发布服务
     * 指定访问url
     * @return
     */
    @Bean
    public Endpoint doCheckEndpoint(){
        EndpointImpl endpoint = new EndpointImpl(bus,doCheckService);
        endpoint.publish("/ccbJgzh");
        endpoint.getOutInterceptors().add( new XmlnsInterceptor(Phase.PREPARE_SEND));
        List sss = endpoint.getInInterceptors();
        return endpoint;
    }
}
